import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import { getBannerList } from '@/api'

export const useBannerStore = defineStore('banner', () => {
  let initedBannerList = ref(false)
  let bannerList = ref([])
  const initBannerListByStore = () => {
    if (!initedBannerList.value) {
      getBannerList().then((r) => {
        r.forEach((item) => {
    
          if(item.my_open_type.open_type === 'channel'){
            const {open_type_config} = item.my_open_type
            item.finderUserName = open_type_config.channel_id
            item.feedId = open_type_config.channel_video_id
            //dev
            item.muted = open_type_config.mute;
            item.loop = open_type_config.loop;
            // item.autoplay = open_type_config.auto_play;
            item.autoplay = open_type_config.auto_play;
          }
          item.type = item.my_open_type.open_type === 'channel' ? 'channel-video':'image'
        })

        bannerList.value = r
      })
    }
  }
  return { bannerList, initBannerListByStore }
})

